% rsts_EFE.M
% compute posterior distribution of expectation formation effects
% Taeyoung Doh
% created: 04/29/2008
%--------------------------------------------------------------------1.0
% house cleaning
%--------------------------------------------------------------------
clear all;
close all;
diary off;

%--------------------------------------------------------------------
% default parameters
%--------------------------------------------------------------------

% call environments and model selection
rsmodel_spec;

%--------------------------------------------------------------------


mhrun = 105; 
mhrunid  = num2str(mhrun','%2.0f');

block1   = 81;		% starting block
blockn   = 100;		% ending block
nsim     = 10000;	% number of simulation draws in each block


%--------------------------------------------------------------------
% model descriptions and basic calculations
%--------------------------------------------------------------------

% parameter names
pnames = feval(fnames_.pnames,msel);


%--------------------------------------------------------------------
% means and standard deviations
%--------------------------------------------------------------------


% load path
 lpath = [path_.para 'mhrun' mhrunid  '/' ];

efe1    = zeros(3,2,2000); 
efe2    = zeros(3,2,2000); 



% loop for block
for jblock=block1:blockn

	% load file
	lfile = [lpath 'mhdraw' num2str(jblock,'%04.0f')];
	load(lfile);
    for j =100:100:10000
        paraj = parasim(j,:)'; 
        paraj = [paraj(1:10);paraj(19:20)];  
        efe1(:,:,(jblock-block1)*100+j/100)=efe(paraj,1); 
        efe2(:,:,(jblock-block1)*100+j/100)=efe(paraj,2); 
    end
end


% save output
sfile = [path_.para 'efe_mhrun' mhrunid '.mat'];
save(sfile,'efe1','efe2');
mefe1  = mean(efe1,3); 
mefe2  = mean(efe2,3); 
sdefe1 = std(efe1,0,3);
sdefe2 = std(efe2,0,3); 


% print log
fmt='%15.8f ';
disp(' ');
disp(' ');
disp(sprintf('-------------------------------------------------------------------------'));
disp(         '');
disp(      'Posterior Means of Expectation Effects'); 
disp( [mefe1 mefe2]); 
disp(      'Posterior Stamdard Deviations of Expectation Effects'); 
disp( [sdefe1 sdefe2]); 

